﻿/*
 * Copyright (c) 2025 HiEasyX
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/**
 * \file Slider.cpp
 * \brief The example of the usage of slider control
 */

#include <include/hex.h>
#include <include/impl/EasyX/hex_impl_easyx.h>

int main() {
	initgraph(640, 480);

	BeginBatchDraw();

	HX::HXInitForEasyX();
	HX::SetBuffer(GetWorkingImage());

	setbkcolor(RGB(180, 180, 180));

	HX::WindowProfile windowProfile;
	windowProfile.Size = { 600, 400 };

	while (true) {
		cleardevice();

		HX::HXBegin();

		ExMessage message{};
		while (peekmessage(&message)) {
			HX::PushMessage(HX::GetHXMessage(&message));
		}

		HX::Window(HXStr("滑动条控件示例"), windowProfile);

		HX::TextProfile titleText;
		titleText.Font.Style = HXFontStyle::Bold;
		titleText.Height = 30;

		{
			HX::Text(HXStr("Float 类型的 Slider"), titleText);

			static float value1 = 0;
			static HX::SliderProfile1f sliderProfile1;
			sliderProfile1.MaxValue = 30;
			sliderProfile1.MinValue = 0;
			HX::Slider1f(HXStr("只有一个分量的 Slider"), value1, sliderProfile1);

			static float value2[2] = {};
			static HX::SliderProfile2f sliderProfile2;
			sliderProfile2[0].MaxValue = 30;
			sliderProfile2[0].MinValue = 0;
			sliderProfile2[1].MaxValue = 10;
			sliderProfile2[1].MinValue = 0;
			HX::Slider2f(HXStr("有两个分量的 Slider，分别设置不同的最值"), value2, sliderProfile2);

			static float value3[3] = {};
			static HX::SliderProfile3f sliderProfile3;
			sliderProfile3[0].MaxValue = 30;
			sliderProfile3[0].MinValue = 0;
			sliderProfile3[1].MaxValue = 10;
			sliderProfile3[1].MinValue = 0;
			sliderProfile3[2].MaxValue = 20;
			sliderProfile3[2].MinValue = 0;
			HX::Slider3f(HXStr("有三个分量的 Slider，分别设置不同的最值"), value3, sliderProfile3);

			static float value4[4] = {};
			static HX::SliderProfile4f sliderProfile4;
			sliderProfile4[0].MaxValue = 30;
			sliderProfile4[0].MinValue = 0;
			sliderProfile4[1].MaxValue = 10;
			sliderProfile4[1].MinValue = 0;
			sliderProfile4[2].MaxValue = 20;
			sliderProfile4[2].MinValue = 0;
			sliderProfile4[3].MaxValue = 90;
			sliderProfile4[3].MinValue = 0;
			HX::Slider4f(HXStr("有四个分量的 Slider，分别设置不同的最值"), value4, sliderProfile4);
		}
		{
			HX::Text(HXStr("Int 类型的 Slider"), titleText);

			static int value1 = 0;
			static HX::SliderProfile1i sliderProfile1;
			sliderProfile1.MaxValue = 30;
			sliderProfile1.MinValue = 0;
			HX::Slider1i(HXStr("只有一个分量的 Slider"), value1, sliderProfile1);

			static int value2[2] = {};
			static HX::SliderProfile2i sliderProfile2;
			sliderProfile2[0].MaxValue = 30;
			sliderProfile2[0].MinValue = 0;
			sliderProfile2[1].MaxValue = 10;
			sliderProfile2[1].MinValue = 0;
			HX::Slider2i(HXStr("有两个分量的 Slider，分别设置不同的最值"), value2, sliderProfile2);

			static int value3[3] = {};
			static HX::SliderProfile3i sliderProfile3;
			sliderProfile3[0].MaxValue = 30;
			sliderProfile3[0].MinValue = 0;
			sliderProfile3[1].MaxValue = 10;
			sliderProfile3[1].MinValue = 0;
			sliderProfile3[2].MaxValue = 20;
			sliderProfile3[2].MinValue = 0;
			HX::Slider3i(HXStr("有三个分量的 Slider，分别设置不同的最值"), value3, sliderProfile3);

			static int value4[4] = {};
			static HX::SliderProfile4i sliderProfile4;
			sliderProfile4[0].MaxValue = 30;
			sliderProfile4[0].MinValue = 0;
			sliderProfile4[1].MaxValue = 10;
			sliderProfile4[1].MinValue = 0;
			sliderProfile4[2].MaxValue = 20;
			sliderProfile4[2].MinValue = 0;
			sliderProfile4[3].MaxValue = 90;
			sliderProfile4[3].MinValue = 0;
			HX::Slider4i(HXStr("有四个分量的 Slider，分别设置不同的最值"), value4, sliderProfile4);
		}

		HX::End();
		HX::Render();

		FlushBatchDraw();

		Sleep(1);
	}

	return 0;
}